home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / VD08SMP.ZIP / usr / samples / gnuplot / controller.m < prev    next >
Encoding:
Text File  |  1996-02-13  |  955 b   |  51 lines

  1. #include "Controller.h"
  2. #include "gnuplot.h"
  3.  
  4. @implementation Controller
  5.  
  6. - init
  7. {
  8.   [super init];
  9.   gnuplot = popen ("gnuplot.exe","w");
  10.   return self;
  11. }
  12.  
  13. - free
  14. {
  15.   pclose (gnuplot);
  16.   return [super free];
  17. }
  18.  
  19. - plot: sender
  20. {
  21.   char   *string;
  22.   char   *leftX,*rightX;
  23.   double  left,right;
  24.  
  25.   string = [[sender findFromID: IDD_PLOTSTRING] text: NULL];
  26.  
  27.   if ([[sender findFromID: IDD_RANGECHECK] checked]) {
  28.     leftX = [[sender findFromID: IDD_LEFTX] text: NULL];
  29.     rightX = [[sender findFromID: IDD_RIGHTX] text: NULL];
  30.  
  31.     if ((sscanf (leftX,"%lf",&left) == 1) &&
  32.     (sscanf (rightX,"%lf",&right) == 1) &&
  33.     (right > left)) {
  34.       fprintf (gnuplot,"plot [%lf:%lf] %s\n",left,right,string);
  35.     } else
  36.       fprintf (gnuplot,"plot %s\n",string);
  37.  
  38.     free (leftX);
  39.     free (rightX);
  40.   } else
  41.     fprintf (gnuplot,"plot %s\n",string);
  42.  
  43.   fflush (gnuplot);
  44.  
  45.   free (string);
  46.  
  47.   return self;
  48. }
  49.  
  50. @end
  51.